const cloud = require('wx-server-sdk')
const env = 'bbq-6gz7knah1c296b0f'
cloud.init(env)

const db = cloud.database({ env })

// 云函数入口函数
exports.main = async (event, context) => {
  var res = await db.collection('talks').where({
    talkers:event.talkers
  }).get()

  var res2 = await db.collection('talks').where({
    talkers:event.talkers.reverse()
  }).get()

  if(!res.data.length && !res2.data.length){
    res = await db.collection('talks').add({
      data:{
        talkers:event.talkers
      }
    })
  }
  return res
}